const Router = require('koa-router');

//控制器
const { addAddress, updateAddress, deleteAddress } = require('../controller/address.controller');

//中间件
const { auth } = require('../middleware/auth.middleware');
const { validator } = require('../middleware/validator.middleware');

const router = new Router({ prefix: '/address' });

//添加地址
router.post('/add', auth, validator({ address_info: 'string', user_tel: 'number', default_address: 'number' }), addAddress);

//更新地址
router.patch('/update', auth, validator({ address_id: 'number', address_info: { type: 'string', required: false }, user_tel: { type: 'number', required: false }, default_address: { type: 'number', required: false } }), updateAddress);

//删除地址
router.delete('/delete', validator({ ids: 'array' }), deleteAddress);

module.exports = router;